package com.cb.controller;

import com.alipay.api.AlipayApiException;
import com.cb.pojo.*;
import com.cb.service.ConductorService;
import com.cb.config.CorsConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.HashMap;

@RestController
@RequestMapping("/conductor")
public class ConductorController {

    @Autowired
    private ConductorService conductorService;

    @Autowired
    CorsConfig corsConfig;

    /**
     * 售票员注册(username,password,yyid,yyname,status)
     * */
    @PostMapping("/register")
    public int userInsert(@RequestBody HashMap json){
        return conductorService.conductorInsert(json);
    }

    /**
     * 售票员登录
     * */
    @PostMapping("/dologin")
    public String login(@RequestBody HashMap json){
        String conductorJson = conductorService.login(json);
        return conductorJson;
    }

    /**
     * 售票员通过用户名username，场次编号ccid，影片名字ypname查询订单
     * */
    @PostMapping("/getOrder")
    public String get(@RequestBody HashMap json){
        return conductorService.getOrder(json);
    }

    /**
     * 开通会员
     * @param json
     * @param request
     * @return
     * @throws AlipayApiException
     */
    @PostMapping("/addmembership")
    public String addMemberShip(@RequestBody HashMap json, HttpServletRequest request) throws AlipayApiException, ParseException {
        return conductorService.addMemberShip(json,request);
    }

    /**
     * 预定
     * @param json
     * @param request
     * @return
     * @throws ParseException
     */
    @PostMapping("/yuding")
    public String yuding(@RequestBody HashMap json,HttpServletRequest request) throws ParseException {
        return conductorService.scheduled(json,request);
    }
    /**
     * 支付
     * @return
     * @throws AlipayApiException
     */
    @PostMapping("/zhifu")
    public String zhifu(@RequestBody HashMap json,HttpServletRequest request) throws AlipayApiException, ParseException {
        return conductorService.filmPly(json,request);
    }

    /**
     * 退款
     * @param json
     * @param request
     * @return
     * @throws ParseException
     * @throws AlipayApiException
     */
    @PostMapping("/refund")
    public String refund(@RequestBody HashMap json,HttpServletRequest request) throws ParseException, AlipayApiException {
        return conductorService.userrefund(json,request);
    }

    /**
     * 在订单处点击改签得按钮判断是不是能改签
     * @param json
     * @param request
     * @return
     * @throws ParseException
     */
    @PostMapping("/changeorder")
    public String changeOrder(@RequestBody HashMap json,HttpServletRequest request) throws ParseException {
        return conductorService.changeOrder(json,request);
    }

    @PostMapping("/qrchangeorder")
    public String qrChangeOrder(@RequestBody HashMap json,HttpServletRequest request) throws ParseException, AlipayApiException {
        return conductorService.qrChangeOrder(json,request);
    }


}
